package com.sky.mapper;

import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {
    /**
     * 根据dish id来查找与菜品所关联的套餐
     * @param dishId
     * @return
     */
    @Select("select setmeal_id from setmeal_dish where dish_id=#{dishId}")
    List<Long> selectBydishId(Long dishId);

    /**
     * 根据 套餐id 来查询所关联的套餐菜品信息
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id=#{id} ")
    List<SetmealDish> SelectSetmealId(Long id);

    /**
     * 新增套餐菜品信息
     * @param setmealDishes
     */
    void savaSetmealDish(List<SetmealDish> setmealDishes);

    /**
     * 查询套餐中的菜品
     * @param id
     * @return
     */
    @Select("select d.* from dish d left join setmeal_dish s on d.id=s.dish_id where s.setmeal_id=#{id}")
    List<Dish> SelectsetmealDish(Long id);

    /**
     * 根据套餐id来删除套餐中菜品
     * @param id
     */
    @Delete("delete from setmeal_dish where setmeal_id=#{id}")
    void delectSetmealId(Long id);

    /**
     * 查询套餐中菜品的信息传递给VO
     * @param id
     * @return
     */
    @Select("select s.name,s.copies,d.image,d.description from setmeal_dish s left join dish d on s.dish_id=d.id where s.setmeal_id=#{id}")
    List<DishItemVO> SelectDishItemVo(Long id);
}
